Wake on LAN

The magic packet is a broadcast frame containing anywhere within its payload 6 bytes of all 255 (FF FF FF FF FF FF in hexadecimal), followed by sixteen repetitions of the target computer's 48-bit MAC address, for a total of 102 bytes.

I don't think will actually work with WiFI...'


In [2]:
import numpy as np

import context
import gopro_helper as gopro

In [ ]:
ssid = 'GP26528824'
# ssid = 'GreenCanoe'

gopro.network.connect_wifi(ssid)

In [ ]:
MAC = 'f6:dd:9e:8f:ae:cf'

def wake_on_lan(mac=MAC):
    """Command remote device to turn on, https://en.wikipedia.org/wiki/Wake-on-LAN
    """
    IP = api.base_addr

    # Verify MAC address format
    if len(mac) == 12:
        pass
    elif len(mac) == 12 + 5:
        sep = mac[2]
        mac = mac.replace(sep, '')
    else:
        raise ValueError('Unexpected MAC address format {}'.format(mac))

    if isinstance(mac, str):
        mac = bytes(mac.encode())

    # Pad the synchronization stream.
    data_FF = np.zeros(dtype=np.uint8,shape=(6))

    data = b''.join([b'FFFFFFFFFFFF', mac * 16])
    send_data = b''

    message = .join([b'FFFFFFFFFFFF', mac * 16])

    # Split up the hex values and pack.
    for i in range(0, len(data), 2):
        send_data = b''.join( [send_data, struct.pack('B', int(data[i: i + 2], 16))] )

    # Broadcast it to the LAN.
    S = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

    # http://www.delorie.com/gnu/docs/glibc/libc_352.html
    S.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

    S.sendto(send_data, (ip, 9))

In [99]:
print(api.url_status)


http://10.5.5.9/gp/gpControl/status

In [ ]:


In [95]:
# https://superuser.com/questions/295325/does-it-matter-what-udp-port-a-wol-signal-is-sent-to